package com.wangxinyuchuan.demo.strategy;

public class ComparableSorter {

    public static void sort(Comparable[] arr) {

        if (null == arr || arr.length == 0 || arr.length == 1) {
            return;
        }

        int length = arr.length;

        for (int i = 0; i < length; i++) {
            int minIndex = i;

            for (int j = i+1; j < length; j++) {
                minIndex = arr[j].compareTo(arr[minIndex]) < 0 ? j : minIndex;
            }

            swap(arr, i, minIndex);
        }

    }

    private static void swap(Comparable[] arr, int i, int minIndex) {
        Comparable temp = arr[i];
        arr[i] = arr[minIndex];
        arr[minIndex] = temp;
    }



}
